/*  File Name	: CommonStruct.h
 *  Author		: Pang Jiacai
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-4-5
 *  Description:
 */

#ifndef COMMONSTRUCT_H_
#define COMMONSTRUCT_H_

#include "Lock.h"

typedef  void* VOID_PTR;
class CommonList
{
public:
	CommonList(int grow_size=256);
	virtual ~CommonList();

	int put_item(VOID_PTR item);
	int get_item(VOID_PTR &item,int index);

	int cur_size(void);
	int max_size(void);

	void reset(void);

protected:
	int grow(void);

private:
	RT_MUTEX mutex_;

	int cur_size_;
	int max_size_;
	int grow_size_;

	VOID_PTR* item_ptr_;
};

///////////////////////////////////////////////

class DuplexList
{
public:
	DuplexList(int size=1024);

	virtual ~DuplexList();

	int put_obj(VOID_PTR obj);
	int get_obj(VOID_PTR &obj);

private:
	int swap_list(void);

	RT_MUTEX read_mutex_;
	RT_MUTEX write_mutex_;

	CommonList *read_list_;
	CommonList *write_list_;
	int cur_read_index_;
};

////////////////////////////////////////////////////

struct ChipsRecord
{
	ChipsRecord()
	{
		role_id =0;
		account ="";
		time = "";
		type =0;
		amount =0;
		cur_bet = 0;
		total_chips =0;
		room = 0;
		table = 0;
		table_index =0;
	}
	int role_id;
	std::string account;
	std::string time;//format:yyyy-mm-dd HH:MM:DD
	int type;
	int amount;
	int cur_bet;
	int total_chips;
	int room;
	int table;
	int table_index;
};

//////////////////////////////
class PlayerBaseInfo
{
public:
	PlayerBaseInfo();
	void set_baseinfo(int roleid,std::string account,std::string name,int sex,int chips=0);
	void reset();

	int role_id(void) const;
	void role_id(int id);

	int sex(void) const;
	void sex(int sex);

	int chips(void) const;
	void chips(int chips);

	std::string account(void) const;
	void account(std::string account);

	std::string name(void) const;
	void name(std::string name);

protected:
	int role_id_;
	int sex_;
	int chips_;
	std::string name_;
	std::string account_;
};

///////////////////////////
struct DBInfo
{
	DBInfo()
	{
		reset();
	}
	void reset(void);
	void set(std::string ip,int port,std::string db,
			std::string user,std::string pwd);
	int port;
	std::string ip;
	std::string dbname;
	std::string user;
	std::string pwd;
};

#endif /* COMMONSTRUCT_H_ */
